package com.itheima.demo;

public class demo_BubbleSort {
    public static void main(String[] args) {
        //创建一个数组;
        int[] arr = {23, 46, 86, 32, 89, 1, 4, 9};

        //外循环控制循环次数;
        for (int i = 0; i < arr.length - 1; i++) {
            //内循环控制对比的次数;
            for (int j = 0; j < arr.length - 1 - i; j++) {
                if (arr[j] > arr[j + 1]) {
                    int temp = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = temp;
                }
            }
        }
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i]+" ");
        }

    }
}
